<div class="layui-row layui-col-space15">
    <form id="businessInfo" lay-filter="businessInfo"
          class="layui-form model-form layui-col-sm12 layui-col-md4 layui-col-lg3">
        <input name="user_id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">公司编号</label>
            <div class="layui-input-block">
                <input name="code" type="text" class="layui-input" readonly style="background:#CCCCCC"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公司名称</label>
            <div class="layui-input-block">
                <input name="name" type="text" class="layui-input" readonly style="background:#CCCCCC"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">管理员账号</label>
            <div class="layui-input-block">
                <input name="username" type="text" class="layui-input" readonly style="background:#CCCCCC"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">管理员姓名</label>
            <div class="layui-input-block">
                <input name="nickname" type="text" class="layui-input" readonly style="background:#CCCCCC"/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="businessInfo-btn-edit" class="layui-btn icon-btn layui-btn layui-btn-sm"><i
                        class="layui-icon">&#xe642;</i>编辑
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input name="status" type="text" class="layui-input" readonly style="background:#CCCCCC"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开通应用</label>
            <div class="layui-input-block">
                <input name="apply" type="text" class="layui-input" readonly style="background:#CCCCCC"/>
            </div>
        </div>
    </form>
</div>

<script>
    layui.use(['layer', 'form', 'admin', 'table'], function () {
        var layer = layui.layer,
            form = layui.form,
            formData = {},
            admin = layui.admin;

        var getInfo = function () {
            var appnames = '';
            admin.req('api-sys/api/entApp/list', {}, function (res) {
                var data = res.data;
                appnames = data.map((obj)=>{return obj.appname}).join(",");
            })
            admin.req('api-sys/api/sysUser/userinfo', {}, function (res) {
                var data = res.ent;
                var userInfo = res.user;
                formData = {
                    code: data.code,
                    name: data.name,
                    username: userInfo.username,
                    nickname: userInfo.nickname,
                    status: '付费用户',
                    ent_id: data.ent_id,
                    apply: appnames
                }
                console.log(formData)
                return formData;
            })
            form.val('businessInfo', formData)
        }
        getInfo()
        // 回显数据

        // 添加按钮点击事件
        $('#businessInfo-btn-edit').click(function () {
            showEditModel(formData);
        });

        var showEditModel = function (data) {
            admin.putTempData('baseData', data);
            admin.popupCenter({
                title: '修改信息',
                path: 'pages/business/baseInfo-form.html',
                finish: function () {
                    getInfo()
                }
            });
        }
    })
</script>
